<!DOCTYPE html>
<html>

	<head>
		<title>我的消息</title>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
		<script src="/js/jquery/jquery.min.js"></script>
		<script src="/js/bootstrap/js/bootstrap.js"></script>
		<link rel="stylesheet" href="/css/font/css/font-awesome.min.css" />
		<link rel="stylesheet" href="/css/reset.css" />
		<link rel="stylesheet" href="/css/message.css" />

		<script>
			$(function () {
			    // 获得当前用户id
			    var user = JSON.parse(sessionStorage.getItem("user"));
                var userId = user.id;

                 // 查询有多少未读评论
                 /*var comment = $.ajax({
                     "dataType": 'json',

                     "url": "/comment/getMessagesByType",
                     "data": {"userId": userId},
                     "success": function (data) {
                         console.log(data);
                         var len = data.length
                         $("#allComments").html(len);
                     }
                 });*/
                 /*----------------------评--------------------论---------------------------------------*/
                 var comment = $.get("/comment/getMessagesByType",{userId:userId},function (data) {
                     //console.log(data);
                     var len = data.length
                     if(len != 0){
                         var html = '<span class="badge badge-danger badge-pill" id="allComments"></span>';
                         $(".c").append(html);
                         $("#allComments").html(len);
                     }

                 })

                // 定时查询有没有未读消息

                var t=setInterval(realTimeGetComment, 2000);//每隔2秒，查询一次
				var req = null;
				function realTimeGetComment() {

					if(req != null){
					    req.abort();
					    req = null;
					}

                    $.ajax({
                        "dataType": 'json',
                        "type":"GET",
                        "url": "/comment/getMessagesByType",
                        "data": {"userId": userId},

                        "success": function (data) {
                            //alert(1)
                            console.log(data);
                            var len = data.length;
                            console.log(len);
                            $("#allComments").html(len);
                        },

                        // 失败提示
                        error:function(){
                            console.log("实时信息，请求失败");
                            clearTimeout(t);
                        }
                    });
                }

                /*-----------------赞--------------------------------------------------------------------------*/
                /*-----------------@------------我-------------的----------------------------------------------*/
                var receiveUserId = userId
                $.get("/atSomeOne/" + receiveUserId,function (data) {
                    if(data != 0){
                        var html = '<span class="badge badge-danger badge-pill" id="UnreadAt"></span>';
                        $(".s").append(html);
                        $("#UnreadAt").html(data);
                    }
                })

                // 定时查询有没有未读消息

                //var t=setInterval(realTimeGetComment3, 2000);//每隔2秒，查询一次
                var req = null;
                function realTimeGetComment3() {

                    if(req != null){
                        req.abort();
                        req = null;
                    }

                    $.ajax({
                        "dataType": 'json',
                        "type":"GET",
                        "url": "/atSomeOne",
                        "data": {"receiveUserId": receiveUserId},

                        "success": function (data) {

                            console.log(data);
                            var len = data.length;
                            console.log(len);
                            $("#UnreadAt").html(len);
                        },

                        // 失败提示
                        error:function(){
                            console.log("实时信息，请求失败");
                            clearTimeout(t);
                        }
                    });
                }

                /*-----------------私------------------------------信------------------------------------------*/

                $.get("/letter/getLetterByState",{userId:userId},function (data) {
                    console.log(data+1);
                    if(data != 0){
                        var html = '<span class="badge badge-danger badge-pill" id="UnreadLetter"></span>';
                        $(".l").append(html);
                        $("#UnreadLetter").html(data);
                    }
                })

                // 定时查询有没有未读消息

                //var t=setInterval(realTimeGetComment2, 2000);//每隔2秒，查询一次
                var req = null;
                function realTimeGetComment2() {

                    if(req != null){
                        req.abort();
                        req = null;
                    }

                    $.ajax({
                        "dataType": 'json',
                        "type":"GET",
                        "url": "/letter/getLetterByState",
                        "data": {"userId": userId},

                        "success": function (data) {

                            console.log(data);
                            var len = data.length;
                            console.log(len);
                            $("#UnreadLetter").html(len);
                        },

                        // 失败提示
                        error:function(){
                            console.log("实时信息，请求失败");
                            clearTimeout(t);
                        }
                    });
                }
                /*-----------------系------------统-----------通------------知----------------------------------*/
                console.log(userId);
                $.get("/sysnotice/getSysnoticeByState",{userId:userId},function (data) {
                    if(data != 0){
                        var html = '<span class="badge badge-danger badge-pill" id="UnreadSysnotice"></span>';
                        $(".s").append(html);
                        $("#UnreadSysnotice").html(data);
                    }
                })

                // 定时查询有没有未读消息

                //var t=setInterval(realTimeGetComment2, 2000);//每隔2秒，查询一次
                var req = null;
                function realTimeGetComment2() {

                    if(req != null){
                        req.abort();
                        req = null;
                    }

                    $.ajax({
                        "dataType": 'json',
                        "type":"GET",
                        "url": "/sysnotice/getSysnoticeByState",
                        "data": {"userId": userId},

                        "success": function (data) {

                            console.log(data);
                            var len = data.length;
                            console.log(len);
                            $("#UnreadSysnotice").html(len);
                        },

                        // 失败提示
                        error:function(){
                            console.log("实时信息，请求失败");
                            clearTimeout(t);
                        }
                    });
                }
            })
		</script>

    </head>

	<body>
		<div class="search-head">
			<div class="row nav-search">
				<div class="col">
					<a href="/mine/profiles.html">
						<span><i class="fa fa-chevron-left" ></i></span>
					</a>
				</div>
				<div class="col">
					<span>我的消息</span>
				</div>
				<div class="col"></div>
			</div>
		</div>

		<ul class="list-group">
			<a href="../../index.html">
				<li class="list-group-item d-flex justify-content-between align-items-center">
					<div class="item">
						<span><i class="fa fa-thumbs-o-up" ></i></span>
						<span>赞</span>
						<span class="badge badge-danger badge-pill">14</span>
					</div>
					<i class="fa fa-chevron-right"></i>
				</li>
			</a>
			<a href="../../index.html">
				<li class="list-group-item d-flex justify-content-between align-items-center">
					<div class="item">
						<span><i class="fa fa-at" ></i></span>
						<span>@我的</span>
						<span class="badge badge-danger badge-pill"></span>
					</div>
					<i class="fa fa-chevron-right"></i>
				</li>
			</a>
			<a href="/mine/message/messagecomment.html">
				<li class="list-group-item d-flex justify-content-between align-items-center">
					<div class="item c">
						<span><i class="fa fa-commenting-o" ></i>	</span>
						<span>评论</span>

					</div>
					<i class="fa fa-chevron-right"></i>
				</li>
			</a>
			<a href="/mine/message/messageletter.html">
				<li class="list-group-item d-flex justify-content-between align-items-center">
					<div class="item l">
						<span><i class="fa fa-envelope-o" ></i></span>
						<span>	私信</span>
						<span class="badge badge-danger badge-pill"></span>
					</div>
					<i class="fa fa-chevron-right"></i>
				</li>
			</a>
			<a href="/mine/message/messageSysnotice.html" id="system">
				<li class="list-group-item d-flex justify-content-between align-items-center">
					<div class="item s">
						<span><i class="fa fa-bell" ></i></span>
						<span>系统通知</span>
						<span class="badge badge-danger badge-pill"></span>
					</div>
					<i class="fa fa-chevron-right"></i>
				</li>
			</a>
		</ul>
		
			<div class="container systemMsg">
					<dl class="itemList">
						<dd>
							<p>如果你无法简洁的表达你的想法，那只说明你还不够了解它。</p> 
							<p>-- 阿尔伯特·爱因斯坦</p>
							<p>32分钟前</p>
                            <span class="badge badge-danger badge-pill"></span>
						</dd>
						<dd>
							<p>如果你无法简洁的表达你的想法，那只说明你还不够了解它。</p> 
							<p>-- 阿尔伯特·爱因斯坦</p>
							<p>32分钟前</p>
						</dd>
					</dl>
				</div>
	</body>

</html>